import {Image, ScrollView, Swiper, SwiperItem, Text, View} from '@tarojs/components';
import Taro from '@tarojs/taro';
import React, {Component} from 'react';
import * as T from '../types';
import './carousel.less';
import actions from '../actions/index';
import {connect} from 'react-redux';
import {store2Props} from '../selectors';
import bannerIcon from '@/assets/image/index/i_banner.png';

type ICarouselProps = T.IProps & T.ICarouselProps;
//@ts-ignore
@connect<Partial<ICarouselProps>, T.ICarouselState>(store2Props, actions)
export default class Info extends Component<Partial<ICarouselProps>, T.ICarouselState> {
  constructor(props: ICarouselProps) {
    super(props);
  }

  bannerClick(url) {
    let itemStr = Taro.getStorageSync('b2b-wechat@login');
    if (!itemStr) {
      Taro.navigateTo({
        url: '/pages/package-C/login/login/index',
      });
      return;
    }
    if (url.indexOf('jsruiyin.com/mobile/') != -1) {
      let arr = url.split('jsruiyin.com/mobile');
      console.log(arr[1]);
      Taro.navigateTo({
        url: arr[1],
      });
    }
  }

  render() {
    let {
      main: {banner},
      actions: {action},
    } = this.props;
    return (
      <View>
        {banner.length > 0 ? (
          <View className="banner-list">
            <Swiper
              indicatorColor="rgba(0,0,0,0.1)"
              indicatorActiveColor="#fff"
              circular
              indicatorDots
              autoplay
              className="banner-swiper"
            >
              {banner.map((item) => {
                return (
                  <SwiperItem>
                    <View
                      onClick={() => {
                        if (item.url) {
                          this.bannerClick(item.url);
                        }
                      }}
                    >
                      <Image src={item.file || bannerIcon} className="banner" mode="aspectFill" />
                    </View>
                  </SwiperItem>
                );
              })}
            </Swiper>
          </View>
        ) : (
          <View className="banner-list">
            <View>
              <Image src={bannerIcon} className="banner" mode="aspectFill" />
            </View>
          </View>
        )}
      </View>
    );
  }
}

//create by moon https://github.com/creasy2010/moon
